package com.example.mobilesafe.home;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.mobilesafe.R;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SplashActivity extends AppCompatActivity {

    @BindView(R.id.tv_version)
    TextView tvVersion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(getPackageName(),0);
            tvVersion.setText("当前版本:V"+info.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            tvVersion.setText("当前版本");
        }
        //利用Timer让此界面延迟3秒后在跳转，timer中有一个线程，这个线程不断执行task
        Timer timer = new Timer();
        //timertask实现Runnable接口，TimerTask类表示在一个指定时间内执行的task
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                //跳转到首界面
                Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
                startActivity(intent);
                SplashActivity.this.finish();
            }
        };
        //设置这个task在延迟三秒之后自动执行
        timer.schedule(task,3000);
    }
}
